package com.elsa.DataStatistics.MQListener;

import com.elsa.DataStatistics.statistics.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class OrderMessageListener {

    @Autowired
    private DayStatistics dayStatistics;

    @Autowired
    private DayMenuStatistics dayMenuStatistics;

    @Autowired
    private DayMPStatistics dayMPStatistics;

    @Autowired
    private DayPersonalStatistics dayPersonalStatistics;

    @Autowired
    private MonthStatistics monthStatistics;

    @Autowired
    private MonthMenuStatistics monthMenuStatistics;

    @Autowired
    private MonthMPStatistics monthMPStatistics;

    @Autowired
    private MonthPersonalStatistics monthPersonalStatistics;

    @Autowired
    private YearStatistics yearStatistics;

    @Autowired
    private YearMenuStatistics yearMenuStatistics;

    @Autowired
    private YearMPStatistics yearMPStatistics;

    @Autowired
    private YearPersonalStatistics yearPersonalStatistics;

    @RabbitListener(queues = "order_queue")
    public void receiveOrderQueue(String oId) throws Exception {

        // 开始时间
        long stime = System.currentTimeMillis();

        // 每日统计
        dayStatistics.dayStatistics(oId);
        dayMenuStatistics.dayStatistics(oId);
        dayMPStatistics.dayMPStatistics(oId);
        dayPersonalStatistics.dayPersonalStatistics(oId);

        // 每月统计
        monthStatistics.monthStatistics(oId);
        monthMenuStatistics.monthStatistics(oId);
        monthMPStatistics.monthMPStatistics(oId);
        monthPersonalStatistics.monthPersonalStatistics(oId);

        // 每年统计
        yearStatistics.yearStatistics(oId);
        yearMenuStatistics.yearStatistics(oId);
        yearMPStatistics.yearMPStatistics(oId);
        yearPersonalStatistics.yearPersonalStatistics(oId);
        // System.out.println("已完成订单统计业务(RabbitMQ Direct order_queue)，id：" + oId);

        // 结束时间
        long etime = System.currentTimeMillis();

        log.info("完成统计时间：" + (etime - stime) + "毫秒。" );

        log.info("已完成订单统计业务(RabbitMQ Direct order_queue)，订单id：" + oId);
    }

}
